﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SharePoint;
using Data.AID;
using Business.AID.Extensions;

namespace Business.AID
{
    public class MetaBO
    {
        #region Propriedades

        private int NumMaxMeta
        {
            get { return 6; }
        }
        private int NumMinMeta
        {
            get { return 3; }
        }

        #endregion

        #region Métodos

        public List<Meta> GetAllGoalsByUser(string userLogin)
        {
            MetaDAO metaDAO = new MetaDAO();
            return metaDAO.GetAllGoalsByUser(userLogin);
        }
        public List<Meta> GetAllGoalsByForm(int idForm)
        {
            MetaDAO metaDAO = new MetaDAO();
            return metaDAO.GetAllGoalsByForm(idForm);
        }
        public Meta GetGoalById(int idGoal)
        {
            MetaDAO metaDAO = new MetaDAO();
            return metaDAO.GetGoalById(idGoal);
        }
        public void DeleteGoal(int idGoal)
        {
            MetaDAO metaDAO = new MetaDAO();
            metaDAO.DeleteGoal(idGoal);
        }
        public void CleanApproval(Meta goal)
        {
            MetaDAO metaDAO = new MetaDAO();
            metaDAO.CleanApproval(goal);

        }
        public void SetGoalApproval(Meta goal)
        {
            MetaDAO metaDAO = new MetaDAO();
            metaDAO.SetAprovacaoMeta(goal);
        }
        public void SetConsideration(Meta goal)
        {
            MetaDAO metaDAO = new MetaDAO();
            metaDAO.SetConsideration(goal);

        }
        public Boolean isValidWeigth(List<Meta> goal)
        {
            int PesoSoma = goal.Sum(p => p.Peso);

            if (PesoSoma == 100)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        public Boolean isValidQuantity(List<Meta> goal)
        {
            int qtdMeta = goal.Count;

            if (qtdMeta >= NumMinMeta && qtdMeta <= NumMaxMeta)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        public Boolean isPopulated(List<Meta> goal)
        {
            foreach (Meta _meta in goal)
            {
                if (_meta.Peso == 0 || _meta.FerramentaMedicao == "(Sem ferramenta)" || _meta.Titulo == "(Sem descrição)")
                {
                    return false;
                }
            }
            return true;
        }
        public void EditMeta(Meta meta) 
        {
            MetaDAO metaDAO = new MetaDAO();
            metaDAO.EditMeta(meta);
        }

        #endregion
    }
}
